<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wrr123.github.io","root":"/","scheme":"Muse","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.json"};
  </script>

  <meta name="description" content="闲时与你立黄昏，笑问灶前粥可温。">
<meta property="og:type" content="article">
<meta property="og:title" content="redis基本使用">
<meta property="og:url" content="https://wrr123.github.io/2021/05/06/redis%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/index.html">
<meta property="og:site_name" content="一缕烟气">
<meta property="og:description" content="闲时与你立黄昏，笑问灶前粥可温。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://localhost:4000/2021/05/06/redis%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/001.png">
<meta property="article:published_time" content="2021-05-06T12:17:49.000Z">
<meta property="article:modified_time" content="2022-02-18T02:52:04.508Z">
<meta property="article:author" content="田园隐士">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://localhost:4000/2021/05/06/redis%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/001.png">

<link rel="canonical" href="https://wrr123.github.io/2021/05/06/redis%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>redis基本使用 | 一缕烟气</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<style>mjx-container[jax="SVG"] {
  direction: ltr;
}

mjx-container[jax="SVG"] > svg {
  overflow: visible;
}

mjx-container[jax="SVG"][display="true"] {
  display: block;
  text-align: center;
  margin: 1em 0;
}

mjx-container[jax="SVG"][justify="left"] {
  text-align: left;
}

mjx-container[jax="SVG"][justify="right"] {
  text-align: right;
}

g[data-mml-node="merror"] > g {
  fill: red;
  stroke: red;
}

g[data-mml-node="merror"] > rect[data-background] {
  fill: yellow;
  stroke: none;
}

g[data-mml-node="mtable"] > line[data-line] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > rect[data-frame] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > .mjx-dashed {
  stroke-dasharray: 140;
}

g[data-mml-node="mtable"] > .mjx-dotted {
  stroke-linecap: round;
  stroke-dasharray: 0,140;
}

g[data-mml-node="mtable"] > svg {
  overflow: visible;
}

[jax="SVG"] mjx-tool {
  display: inline-block;
  position: relative;
  width: 0;
  height: 0;
}

[jax="SVG"] mjx-tool > mjx-tip {
  position: absolute;
  top: 0;
  left: 0;
}

mjx-tool > mjx-tip {
  display: inline-block;
  padding: .2em;
  border: 1px solid #888;
  font-size: 70%;
  background-color: #F8F8F8;
  color: black;
  box-shadow: 2px 2px 5px #AAAAAA;
}

g[data-mml-node="maction"][data-toggle] {
  cursor: pointer;
}

mjx-status {
  display: block;
  position: fixed;
  left: 1em;
  bottom: 1em;
  min-width: 25%;
  padding: .2em .4em;
  border: 1px solid #888;
  font-size: 90%;
  background-color: #F8F8F8;
  color: black;
}

foreignObject[data-mjx-xml] {
  font-family: initial;
  line-height: normal;
  overflow: visible;
}

.MathJax path {
  stroke-width: 3;
}

mjx-container[display="true"] {
  overflow: auto hidden;
}

mjx-container[display="true"] + br {
  display: none;
}
</style><link rel="alternate" href="/atom.xml" title="一缕烟气" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">一缕烟气</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">沧海月明珠有泪，蓝田日暖玉生烟</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wrr123.github.io/2021/05/06/redis%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="田园隐士">
      <meta itemprop="description" content="talk is cheap, show me the code">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一缕烟气">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          redis基本使用
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-05-06 20:17:49" itemprop="dateCreated datePublished" datetime="2021-05-06T20:17:49+08:00">2021-05-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-02-18 10:52:04" itemprop="dateModified" datetime="2022-02-18T10:52:04+08:00">2022-02-18</time>
              </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>8.2k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><span style="color:Chocolate;text-align:center;display:inline-block;width:100%;">闲时与你立黄昏，笑问灶前粥可温。</span><br><span id="more"></span></p>
<h4 id="基本命令"><a href="#基本命令" class="headerlink" title="基本命令"></a>基本命令</h4><ol>
<li>查询所有的key <code>keys *</code></li>
<li>设置一个key <code>set name 'HelloWorld'</code></li>
<li>获取指定key的值 <code>get name</code></li>
<li>设置一个hash <code>HMSET runoobkey name "redis tutorial" description "redis basic commands for caching" likes 20 visitors 23000</code></li>
<li>获取hash值 <code>HGETALL runoobkey</code></li>
<li>添加列表 <code>LPUSH runoobkey redis</code></li>
<li>查询列表 <code>lrange runoobkey 0 10</code></li>
<li>添加集合 <code>sadd a redis</code></li>
<li>查询集合 <code>smembers a</code></li>
<li>添加有序集合 <code>zadd a 1 test1</code></li>
<li>查询有序集合 <code>zrange a 0 10</code></li>
<li>添加HyperLogLog <code>pfadd a test1</code></li>
<li>查询HyperLogLog <code>pfcount a</code></li>
</ol>
<h4 id="发布订阅"><a href="#发布订阅" class="headerlink" title="发布订阅"></a>发布订阅</h4><p>Redis发布订阅（pub/sub）是一种消息通信模式:发送者（pub）发送消息，订阅者（sub）接收消息。</p>
<h4 id="springboot集成redis"><a href="#springboot集成redis" class="headerlink" title="springboot集成redis"></a>springboot集成redis</h4><ol>
<li><p>添加依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-data-redis<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>springboot容器中已经有了redis的一个自动装配类<code>StringRedisTemplate</code>，如果你操作都是使用的String的数据类型，那么可以直接使用。</p>
</li>
<li><p>自定义RedisTemplate</p>
</li>
</ol>
<h4 id="gradle构建springboot"><a href="#gradle构建springboot" class="headerlink" title="gradle构建springboot"></a>gradle构建springboot</h4><p>在idea中按照步骤建立项目即可。</p>
<h4 id="springboot集成基本的web项目"><a href="#springboot集成基本的web项目" class="headerlink" title="springboot集成基本的web项目"></a>springboot集成基本的web项目</h4><h4 id="springboot集成druid-mysql"><a href="#springboot集成druid-mysql" class="headerlink" title="springboot集成druid-mysql"></a>springboot集成druid-mysql</h4><ol>
<li><p>引入依赖</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// springboot整合druid</span></span><br><span class="line">implementation <span class="string">'com.alibaba:druid-spring-boot-starter:1.1.22'</span></span><br><span class="line"><span class="comment">// mysql驱动</span></span><br><span class="line">implementation <span class="string">'mysql:mysql-connector-java'</span></span><br><span class="line"><span class="comment">// springboot整合jdbc</span></span><br><span class="line">implementation <span class="string">'org.springframework.boot:spring-boot-starter-jdbc'</span></span><br><span class="line"><span class="comment">// springboot整合mybatis</span></span><br><span class="line">implementation <span class="string">'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1'</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>修改yml配置文件，整合配置druid</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line">    <span class="comment"># 数据库访问配置, 使用druid数据源(默认数据源是HikariDataSource)</span></span><br><span class="line">    <span class="attr">type:</span> <span class="string">com.alibaba.druid.pool.DruidDataSource</span></span><br><span class="line">    <span class="comment">#链接池配置</span></span><br><span class="line">    <span class="attr">druid:</span></span><br><span class="line">      <span class="attr">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line">      <span class="attr">url:</span> <span class="string">jdbc:mysql://localhost:3306/springboot?useUnicode=true&amp;characterEncoding=UTF-8&amp;useSSL=false&amp;serverTimezone=GMT%2B8</span></span><br><span class="line">      <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">      <span class="attr">password:</span> <span class="string">xsge</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># 连接池配置：大小，最小，最大</span></span><br><span class="line">      <span class="attr">initial-size:</span> <span class="number">5</span></span><br><span class="line">      <span class="attr">min-idle:</span> <span class="number">5</span></span><br><span class="line">      <span class="attr">max-active:</span> <span class="number">20</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># 连接等待超时时间</span></span><br><span class="line">      <span class="attr">max-wait:</span> <span class="number">30000</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># 配置检测可以关闭的空闲连接，间隔时间</span></span><br><span class="line">      <span class="attr">time-between-eviction-runs-millis:</span> <span class="number">60000</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># 配置连接在池中的最小生存时间</span></span><br><span class="line">      <span class="attr">min-evictable-idle-time-millis:</span> <span class="number">300000</span></span><br><span class="line">      <span class="comment"># 检测连接是否有，有效得select语句</span></span><br><span class="line">      <span class="attr">validation-query:</span> <span class="string">select</span> <span class="string">'1'</span> <span class="string">from</span> <span class="string">dual</span></span><br><span class="line">      <span class="comment"># 申请连接的时候检测，如果空闲时间大于time-between-eviction-runs-millis，执行validationQuery检测连接是否有效，建议配置为true，不影响性能，并且保证安全性。</span></span><br><span class="line">      <span class="attr">test-while-idle:</span> <span class="literal">true</span></span><br><span class="line">      <span class="comment"># 申请连接时执行validationQuery检测连接是否有效，建议设置为false，不然会会降低性能</span></span><br><span class="line">      <span class="attr">test-on-borrow:</span> <span class="literal">false</span></span><br><span class="line">      <span class="comment"># 归还连接时执行validationQuery检测连接是否有效，建议设置为false，不然会会降低性能</span></span><br><span class="line">      <span class="attr">test-on-return:</span> <span class="literal">false</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># 是否缓存preparedStatement，也就是PSCache  官方建议MySQL下建议关闭   个人建议如果想用SQL防火墙 建议打开</span></span><br><span class="line">      <span class="comment"># 打开PSCache，并且指定每个连接上PSCache的大小</span></span><br><span class="line">      <span class="attr">pool-prepared-statements:</span> <span class="literal">true</span></span><br><span class="line">      <span class="attr">max-open-prepared-statements:</span> <span class="number">20</span></span><br><span class="line">      <span class="attr">max-pool-prepared-statement-per-connection-size:</span> <span class="number">20</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># 配置监控统计拦截的filters, 去掉后监控界面sql无法统计, 'wall'用于防火墙防御sql注入，stat监控统计,logback日志</span></span><br><span class="line">      <span class="attr">filters:</span> <span class="string">stat,wall</span></span><br><span class="line">      <span class="comment"># Spring监控AOP切入点，如x.y.z.service.*,配置多个英文逗号分隔</span></span><br><span class="line">      <span class="comment">#aop-patterns: com.springboot.servie.*</span></span><br><span class="line">      <span class="comment"># lowSqlMillis用来配置SQL慢的标准，执行时间超过slowSqlMillis的就是慢</span></span><br><span class="line">      <span class="attr">connectionProperties:</span> <span class="string">druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># WebStatFilter监控配置</span></span><br><span class="line">      <span class="attr">web-stat-filter:</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line">        <span class="comment"># 添加过滤规则：那些访问拦截统计</span></span><br><span class="line">        <span class="attr">url-pattern:</span> <span class="string">/*</span></span><br><span class="line">        <span class="comment"># 忽略过滤的格式：哪些不拦截，不统计</span></span><br><span class="line">        <span class="attr">exclusions:</span> <span class="string">'*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*'</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># StatViewServlet配置（Druid监控后台的Servlet映射配置，因为SpringBoot项目没有web.xml所在在这里使用配置文件设置）</span></span><br><span class="line">      <span class="attr">stat-view-servlet:</span></span><br><span class="line">        <span class="attr">enabled:</span> <span class="literal">true</span></span><br><span class="line">        <span class="comment"># 配置Servlet的访问路径：访问路径为/druid/**时，跳转到StatViewServlet，会自动转到Druid监控后台</span></span><br><span class="line">        <span class="attr">url-pattern:</span> <span class="string">/druid/*</span></span><br><span class="line">        <span class="comment"># 是否能够重置数据</span></span><br><span class="line">        <span class="attr">reset-enable:</span> <span class="literal">false</span></span><br><span class="line">        <span class="comment"># 设置监控后台的访问账户及密码</span></span><br><span class="line">        <span class="attr">login-username:</span> <span class="string">xsge</span></span><br><span class="line">        <span class="attr">login-password:</span> <span class="string">xsge</span></span><br><span class="line">        <span class="comment"># IP白名单：允许哪些主机访问，默认为“”任何主机</span></span><br><span class="line">        <span class="comment"># allow: 127.0.0.1</span></span><br><span class="line">        <span class="comment"># IP黑名单：禁止IP访问，（共同存在时，deny优先于allow）</span></span><br><span class="line">        <span class="comment"># deny: 192.168.1.218</span></span><br><span class="line"></span><br><span class="line">      <span class="comment"># 配置StatFilter</span></span><br><span class="line">      <span class="attr">filter:</span></span><br><span class="line">        <span class="attr">stat:</span></span><br><span class="line">          <span class="attr">log-slow-sql:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure>
</li>
</ol>
<h4 id="springboot集成mybatis"><a href="#springboot集成mybatis" class="headerlink" title="springboot集成mybatis"></a>springboot集成mybatis</h4><ol>
<li><p>依赖引入</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">implementation <span class="string">'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.0.1'</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>mapper接口可以基于注解方式或xml方式。</p>
</li>
<li><p>修改yaml文件，进行mybatis配置</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># MyBatis配置</span></span><br><span class="line"><span class="attr">mybatis:</span></span><br><span class="line">  <span class="comment"># 指定pojo扫描包来让mybatis自动扫描到自定义的pojo</span></span><br><span class="line">  <span class="comment"># 可以不需要写类的全称类名，只需要写简单类名即可。</span></span><br><span class="line">  <span class="attr">type-aliases-package:</span> <span class="string">com.xsge.app.entity</span></span><br><span class="line">  <span class="comment"># 配置XML扫描地址</span></span><br><span class="line">  <span class="attr">mapper-locations:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">classpath:mapper/*.xml</span></span><br><span class="line">  <span class="comment"># 配置启用驼峰命名方式</span></span><br><span class="line">  <span class="attr">configuration:</span></span><br><span class="line">    <span class="attr">map-underscore-to-camel-case:</span> <span class="literal">true</span></span><br><span class="line"><span class="comment"># 设置日志级别</span></span><br><span class="line"><span class="attr">logging:</span></span><br><span class="line">  <span class="attr">level:</span></span><br><span class="line">    <span class="comment"># 以包前置，表示指定包下的操作日志级别</span></span><br><span class="line">    <span class="attr">personal.wd.demo:</span> <span class="string">debug</span>    </span><br></pre></td></tr></table></figure>
</li>
</ol>
<h4 id="springboot整合MyBatis分页助手"><a href="#springboot整合MyBatis分页助手" class="headerlink" title="springboot整合MyBatis分页助手"></a>springboot整合MyBatis分页助手</h4><ol>
<li><p>引入依赖</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">implementation <span class="string">'com.github.pagehelper:pagehelper-spring-boot-starter:1.2.12'</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>java测试类</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping("pagehelper")</span></span><br><span class="line"><span class="keyword">public</span> PageInfo&lt;SysUserEntity&gt; <span class="title function_">selectUserList</span><span class="params">()</span> {</span><br><span class="line">    <span class="comment">// 1. 执行分页</span></span><br><span class="line">    PageHelper.startPage(<span class="number">2</span>, <span class="number">1</span>);</span><br><span class="line">    <span class="comment">// 2. 执行查询</span></span><br><span class="line">    List&lt;SysUserEntity&gt; list = sysUserDao.selectUserList();</span><br><span class="line">    <span class="comment">// 3. 封装PageInfo对象</span></span><br><span class="line">    PageInfo&lt;SysUserEntity&gt; pageInfo = <span class="keyword">new</span> <span class="title class_">PageInfo</span>&lt;&gt;(list);</span><br><span class="line">    <span class="keyword">return</span> pageInfo;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
</li>
</ol>
<h5 id="分页插件支持的调用方式"><a href="#分页插件支持的调用方式" class="headerlink" title="分页插件支持的调用方式"></a>分页插件支持的调用方式</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//第一种，RowBounds方式的调用</span></span><br><span class="line">List&lt;Country&gt; list = sqlSession.selectList(<span class="string">"x.y.selectIf"</span>, <span class="literal">null</span>, <span class="keyword">new</span> <span class="title class_">RowBounds</span>(<span class="number">0</span>, <span class="number">10</span>));</span><br><span class="line"></span><br><span class="line"><span class="comment">//第二种，Mapper接口方式的调用，推荐这种使用方式。</span></span><br><span class="line">PageHelper.startPage(<span class="number">1</span>, <span class="number">10</span>);</span><br><span class="line">List&lt;Country&gt; list = countryMapper.selectIf(<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//第三种，Mapper接口方式的调用，推荐这种使用方式。</span></span><br><span class="line">PageHelper.offsetPage(<span class="number">1</span>, <span class="number">10</span>);</span><br><span class="line">List&lt;Country&gt; list = countryMapper.selectIf(<span class="number">1</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//第四种，参数方法调用</span></span><br><span class="line"><span class="comment">//存在以下 Mapper 接口方法，你不需要在 xml 处理后两个参数</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">CountryMapper</span> {</span><br><span class="line">    List&lt;Country&gt; <span class="title function_">selectByPageNumSize</span><span class="params">(</span></span><br><span class="line"><span class="params">            <span class="meta">@Param("user")</span> User user,</span></span><br><span class="line"><span class="params">            <span class="meta">@Param("pageNum")</span> <span class="type">int</span> pageNum,</span></span><br><span class="line"><span class="params">            <span class="meta">@Param("pageSize")</span> <span class="type">int</span> pageSize)</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">//配置supportMethodsArguments=true</span></span><br><span class="line"><span class="comment">//在代码中直接调用：</span></span><br><span class="line">List&lt;Country&gt; list = countryMapper.selectByPageNumSize(user, <span class="number">1</span>, <span class="number">10</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//第五种，参数对象</span></span><br><span class="line"><span class="comment">//如果 pageNum 和 pageSize 存在于 User 对象中，只要参数有值，也会被分页</span></span><br><span class="line"><span class="comment">//有如下 User 对象</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">User</span> {</span><br><span class="line">    <span class="comment">//其他fields</span></span><br><span class="line">    <span class="comment">//下面两个参数名和 params 配置的名字一致</span></span><br><span class="line">    <span class="keyword">private</span> Integer pageNum;</span><br><span class="line">    <span class="keyword">private</span> Integer pageSize;</span><br><span class="line">}</span><br><span class="line"><span class="comment">//存在以下 Mapper 接口方法，你不需要在 xml 处理后两个参数</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">interface</span> <span class="title class_">CountryMapper</span> {</span><br><span class="line">    List&lt;Country&gt; <span class="title function_">selectByPageNumSize</span><span class="params">(User user)</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">//当 user 中的 pageNum!= null &amp;&amp; pageSize!= null 时，会自动分页</span></span><br><span class="line">List&lt;Country&gt; list = countryMapper.selectByPageNumSize(user);</span><br><span class="line"></span><br><span class="line"><span class="comment">//第六种，ISelect 接口方式</span></span><br><span class="line"><span class="comment">//jdk6,7用法，创建接口</span></span><br><span class="line">Page&lt;Country&gt; page = PageHelper.startPage(<span class="number">1</span>, <span class="number">10</span>).doSelectPage(<span class="keyword">new</span> <span class="title class_">ISelect</span>() {</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">doSelect</span><span class="params">()</span> {</span><br><span class="line">        countryMapper.selectGroupBy();</span><br><span class="line">    }</span><br><span class="line">});</span><br><span class="line"><span class="comment">//jdk8 lambda用法</span></span><br><span class="line">Page&lt;Country&gt; page = PageHelper.startPage(<span class="number">1</span>, <span class="number">10</span>).doSelectPage(()-&gt; countryMapper.selectGroupBy());</span><br><span class="line"></span><br><span class="line"><span class="comment">//也可以直接返回PageInfo，注意doSelectPageInfo方法和doSelectPage</span></span><br><span class="line">pageInfo = PageHelper.startPage(<span class="number">1</span>, <span class="number">10</span>).doSelectPageInfo(<span class="keyword">new</span> <span class="title class_">ISelect</span>() {</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">doSelect</span><span class="params">()</span> {</span><br><span class="line">        countryMapper.selectGroupBy();</span><br><span class="line">    }</span><br><span class="line">});</span><br><span class="line"><span class="comment">//对应的lambda用法</span></span><br><span class="line">pageInfo = PageHelper.startPage(<span class="number">1</span>, <span class="number">10</span>).doSelectPageInfo(() -&gt; countryMapper.selectGroupBy());</span><br><span class="line"></span><br><span class="line"><span class="comment">//count查询，返回一个查询语句的count数</span></span><br><span class="line"><span class="type">long</span> <span class="variable">total</span> <span class="operator">=</span> PageHelper.count(<span class="keyword">new</span> <span class="title class_">ISelect</span>() {</span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">doSelect</span><span class="params">()</span> {</span><br><span class="line">        countryMapper.selectLike(country);</span><br><span class="line">    }</span><br><span class="line">});</span><br><span class="line"><span class="comment">//lambda</span></span><br><span class="line">total = PageHelper.count(()-&gt;countryMapper.selectLike(country));</span><br></pre></td></tr></table></figure>
<h4 id="springboot集成mybatis-plus"><a href="#springboot集成mybatis-plus" class="headerlink" title="springboot集成mybatis-plus"></a>springboot集成mybatis-plus</h4><ol>
<li><p>引入依赖</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">implementation <span class="string">'com.baomidou:mybatis-plus-boot-starter:3.0.5'</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>dao层继承类<code>BaseMapper&lt;T&gt;</code></p>
</li>
<li><p>service接口层继承类<code>IService&lt;T&gt;</code></p>
</li>
<li><p>service实现层继承类<code>ServiceImpl&lt;M extends BaseMapper&lt;T&gt;, T&gt;</code>,实现自己定义的service接口</p>
</li>
</ol>
<h4 id="sprigboot集成多数据源"><a href="#sprigboot集成多数据源" class="headerlink" title="sprigboot集成多数据源"></a>sprigboot集成多数据源</h4><ol>
<li><p>引入依赖</p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">implementation <span class="string">'com.baomidou:dynamic-datasource-spring-boot-starter:3.3.2'</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>配置数据源</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line">    <span class="attr">dynamic:</span></span><br><span class="line">      <span class="attr">primary:</span> <span class="string">master</span> <span class="comment">#设置默认的数据源或者数据源组,默认值即为master</span></span><br><span class="line">      <span class="attr">strict:</span> <span class="literal">false</span> <span class="comment">#设置严格模式,默认false不启动. 启动后在未匹配到指定数据源时候会抛出异常,不启动则使用默认数据源.</span></span><br><span class="line">      <span class="attr">datasource:</span></span><br><span class="line">        <span class="attr">master:</span></span><br><span class="line">          <span class="attr">url:</span> <span class="string">jdbc:mysql://xx.xx.xx.xx:3306/dynamic</span></span><br><span class="line">          <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">          <span class="attr">password:</span> <span class="number">123456</span></span><br><span class="line">          <span class="attr">driver-class-name:</span> <span class="string">com.mysql.jdbc.Driver</span> <span class="comment"># 3.2.0开始支持SPI可省略此配置</span></span><br><span class="line">        <span class="attr">slave_1:</span></span><br><span class="line">          <span class="attr">url:</span> <span class="string">jdbc:mysql://xx.xx.xx.xx:3307/dynamic</span></span><br><span class="line">          <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">          <span class="attr">password:</span> <span class="number">123456</span></span><br><span class="line">          <span class="attr">driver-class-name:</span> <span class="string">com.mysql.jdbc.Driver</span></span><br><span class="line">        <span class="attr">slave_2:</span></span><br><span class="line">          <span class="attr">url:</span> <span class="string">ENC(xxxxx)</span> <span class="comment"># 内置加密,使用请查看详细文档</span></span><br><span class="line">          <span class="attr">username:</span> <span class="string">ENC(xxxxx)</span></span><br><span class="line">          <span class="attr">password:</span> <span class="string">ENC(xxxxx)</span></span><br><span class="line">          <span class="attr">driver-class-name:</span> <span class="string">com.mysql.jdbc.Driver</span></span><br><span class="line">          <span class="attr">schema:</span> <span class="string">db/schema.sql</span> <span class="comment"># 配置则生效,自动初始化表结构</span></span><br><span class="line">          <span class="attr">data:</span> <span class="string">db/data.sql</span> <span class="comment"># 配置则生效,自动初始化数据</span></span><br><span class="line">          <span class="attr">continue-on-error:</span> <span class="literal">true</span> <span class="comment"># 默认true,初始化失败是否继续</span></span><br><span class="line">          <span class="attr">separator:</span> <span class="string">";"</span> <span class="comment"># sql默认分号分隔符</span></span><br><span class="line">          </span><br><span class="line">       <span class="comment">#......省略</span></span><br><span class="line">       <span class="comment">#以上会配置一个默认库master，一个组slave下有两个子库slave_1,slave_2</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>使用<code>@DS</code>注解切换数据源</p>
</li>
</ol>
<h4 id="springboot整合shiro"><a href="#springboot整合shiro" class="headerlink" title="springboot整合shiro"></a>springboot整合shiro</h4><h5 id="shiro三大核心组件"><a href="#shiro三大核心组件" class="headerlink" title="shiro三大核心组件"></a>shiro三大核心组件</h5><ol>
<li><p>subject为认证主体</p>
<ul>
<li><p>Principals：代表身份。可以是用户名、邮件、手机号码等等，用来标识一个登录主体的身份。</p>
</li>
<li><p>Credentials：代表凭证。常见的有密码，数字证书等等。</p>
</li>
</ul>
</li>
<li><p>SecurityManager为安全管理员</p>
</li>
<li><p>Realm是一个域</p>
</li>
</ol>
<h5 id="shiro身份和权限认证"><a href="#shiro身份和权限认证" class="headerlink" title="shiro身份和权限认证"></a>shiro身份和权限认证</h5><ol>
<li><p>shiro身份认证</p>
<p><img src="http://localhost:4000/2021/05/06/redis%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/001.png" alt></p>
<ul>
<li>应用程序代码调用<code>Subject.login(token)</code>方法后，传入代表最终用户的AuthenticationToken实例Token。</li>
<li>将Subject实例委托给应用程序的<code>SecurityManager</code>(shiro的安全管理)，并开始实际的认证工作。</li>
<li><code>SecurityManager</code>根据具体的<code>Realm</code>进行安全认证。</li>
</ul>
</li>
<li><p>shiro权限认证</p>
<ul>
<li>权限（Permission）：即操作资源的权利，比如访问某个界面，以及对某个模块的数据进行添加、修改、查看操作的权利。</li>
<li>角色（Role）：指的是用户担任的角色，一个角色可以有多个权限。</li>
<li>用户（User）：在shiro中，代表访问系统的用户，即上面提到的subject认证主体。</li>
</ul>
</li>
</ol>
<h5 id="springboot集成shiro"><a href="#springboot集成shiro" class="headerlink" title="springboot集成shiro"></a>springboot集成shiro</h5><ol>
<li>依赖导入<ol>
<li><code>implementation 'org.apache.shiro:shiro-spring:1.6.0'</code></li>
</ol>
</li>
<li>数据库表的建立和初始化<ol>
<li>user 用户</li>
<li>role 角色</li>
<li>menu 权限</li>
</ol>
</li>
<li>自定义Realm<ol>
<li>重写其中的权限认证</li>
<li>重写其中的登录认证</li>
</ol>
</li>
<li>shiro配置<ol>
<li>将自定义的realm加入spring容器</li>
<li>将自定义的realm设置到securityManager中，并加入spring容器中</li>
<li>将securityManager设置到shiroFilterFactoryBean中，并加入到spring容器中</li>
</ol>
</li>
<li>使用shiro进行认证<ol>
<li>在系统的登录接口中，创建subject认证主体、usernamepasswordToken，进行登录认证</li>
<li>可以对类<code>AuthenticationToken</code>进行重写，重写其中的<code>getPrincipal</code>和<code>getCredentials</code>方法，按照自己的需求传递字段，如token，username，password等等。</li>
</ol>
</li>
</ol>
<h4 id><a href="#" class="headerlink" title=" "></a> </h4>
    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/05/06/vop-cdc%E6%8E%A5%E5%8F%A3%E4%BF%AE%E6%94%B9/" rel="prev" title="vop-cdc接口修改">
      <i class="fa fa-chevron-left"></i> vop-cdc接口修改
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/05/09/springboot%E9%9B%86%E6%88%90%E6%95%99%E7%A8%8B/" rel="next" title="springboot集成教程">
      springboot集成教程 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9F%BA%E6%9C%AC%E5%91%BD%E4%BB%A4"><span class="nav-number">1.</span> <span class="nav-text">基本命令</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%91%E5%B8%83%E8%AE%A2%E9%98%85"><span class="nav-number">2.</span> <span class="nav-text">发布订阅</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#springboot%E9%9B%86%E6%88%90redis"><span class="nav-number">3.</span> <span class="nav-text">springboot集成redis</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#gradle%E6%9E%84%E5%BB%BAspringboot"><span class="nav-number">4.</span> <span class="nav-text">gradle构建springboot</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#springboot%E9%9B%86%E6%88%90%E5%9F%BA%E6%9C%AC%E7%9A%84web%E9%A1%B9%E7%9B%AE"><span class="nav-number">5.</span> <span class="nav-text">springboot集成基本的web项目</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#springboot%E9%9B%86%E6%88%90druid-mysql"><span class="nav-number">6.</span> <span class="nav-text">springboot集成druid-mysql</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#springboot%E9%9B%86%E6%88%90mybatis"><span class="nav-number">7.</span> <span class="nav-text">springboot集成mybatis</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#springboot%E6%95%B4%E5%90%88MyBatis%E5%88%86%E9%A1%B5%E5%8A%A9%E6%89%8B"><span class="nav-number">8.</span> <span class="nav-text">springboot整合MyBatis分页助手</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%88%86%E9%A1%B5%E6%8F%92%E4%BB%B6%E6%94%AF%E6%8C%81%E7%9A%84%E8%B0%83%E7%94%A8%E6%96%B9%E5%BC%8F"><span class="nav-number">8.1.</span> <span class="nav-text">分页插件支持的调用方式</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#springboot%E9%9B%86%E6%88%90mybatis-plus"><span class="nav-number">9.</span> <span class="nav-text">springboot集成mybatis-plus</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#sprigboot%E9%9B%86%E6%88%90%E5%A4%9A%E6%95%B0%E6%8D%AE%E6%BA%90"><span class="nav-number">10.</span> <span class="nav-text">sprigboot集成多数据源</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#springboot%E6%95%B4%E5%90%88shiro"><span class="nav-number">11.</span> <span class="nav-text">springboot整合shiro</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#shiro%E4%B8%89%E5%A4%A7%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6"><span class="nav-number">11.1.</span> <span class="nav-text">shiro三大核心组件</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#shiro%E8%BA%AB%E4%BB%BD%E5%92%8C%E6%9D%83%E9%99%90%E8%AE%A4%E8%AF%81"><span class="nav-number">11.2.</span> <span class="nav-text">shiro身份和权限认证</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#springboot%E9%9B%86%E6%88%90shiro"><span class="nav-number">11.3.</span> <span class="nav-text">springboot集成shiro</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link"><span class="nav-number">12.</span> <span class="nav-text"> </span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">田园隐士</p>
  <div class="site-description" itemprop="description">talk is cheap, show me the code</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">347</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
        <span class="site-state-item-count">53</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">田园隐士</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">587k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">8:53</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  
      

<script>
  if (typeof MathJax === 'undefined') {
    window.MathJax = {
      loader: {
          load: ['[tex]/mhchem'],
        source: {
          '[tex]/amsCd': '[tex]/amscd',
          '[tex]/AMScd': '[tex]/amscd'
        }
      },
      tex: {
        inlineMath: {'[+]': [['$', '$']]},
          packages: {'[+]': ['mhchem']},
        tags: 'ams'
      },
      options: {
        renderActions: {
          findScript: [10, doc => {
            document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
              const display = !!node.type.match(/; *mode=display/);
              const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
              const text = document.createTextNode('');
              node.parentNode.replaceChild(text, node);
              math.start = {node: text, delim: '', n: 0};
              math.end = {node: text, delim: '', n: 0};
              doc.math.push(math);
            });
          }, '', false],
          insertedScript: [200, () => {
            document.querySelectorAll('mjx-container').forEach(node => {
              let target = node.parentNode;
              if (target.nodeName.toLowerCase() === 'li') {
                target.parentNode.classList.add('has-jax');
              }
            });
          }, '', false]
        }
      }
    };
    (function () {
      var script = document.createElement('script');
      script.src = '//cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js';
      script.defer = true;
      document.head.appendChild(script);
    })();
  } else {
    MathJax.startup.document.state(0);
    MathJax.texReset();
    MathJax.typeset();
  }
</script>

    

  

</body>
</html>
